<?php
   @session_start();
   $width = 55 ;
   $height = 25;
   $length = 4;

   $im = imagecreatetruecolor($width, $height);
   $black = imagecolorallocate($im, 35, 140, 195);
   imagefill($im, 0, 0, $black);
   $string = 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,1,2,3,4,5,6,7,8,9,0';
   $data = explode(',', $string);
   $sum  = count($data)-1;
   for($i=0;$i<$length;$i++)
   {
	  $num = rand(0, $sum);
	  $new_str .= $data[$num];
   }
 
   $_SESSION['login_code'] = $new_str;

   //字体颜色====================
   $font_color = imagecolorallocate($im, 255, 255, 255);
   //画点========================
   $pixcolor = imagecolorallocate($im, 255, 255, 255);
	for ($i = 0; $i < 150; $i++) {
		imagesetpixel($im, rand(1, 100), rand(1, 30), $pixcolor);
	}  
   //边框========================
   $boder = imagecolorallocate($im, 177,177,177);
   imagerectangle($im, 0, 0, $width-1, $height-1, $boder);
   imagestring($im,6, 10, 5, $new_str, $font_color);
   ob_clean();
   header('Content-type: image/png');
   imagepng($im);
   imagedestroy($im);
?>
